package com.dq.Week3.day13.mail;

import java.util.Date;
import java.util.Objects;

public class MailInfo implements Comparable<MailInfo>{

    // 发件人
    private String sender;
    // 邮件标题
    private String title;

    // 发件日期
    private Date sendDate;

    // 收件人
    private String receiver;

    public MailInfo() {
    }

    public MailInfo(String sender, String title, Date sendDate, String receiver) {
        this.sender = sender;
        this.title = title;
        this.sendDate = sendDate;
        this.receiver = receiver;
    }

    public String getSender() {
        return sender;
    }

    public void setSender(String sender) {
        this.sender = sender;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getSendDate() {
        return sendDate;
    }

    public void setSendDate(Date sendDate) {
        this.sendDate = sendDate;
    }

    public String getReceiver() {
        return receiver;
    }

    public void setReceiver(String receiver) {
        this.receiver = receiver;
    }

    @Override
    public String toString() {
        return "MailInfo{" +
                "sender='" + sender + '\'' +
                ", title='" + title + '\'' +
                ", sendDate=" + sendDate +
                ", receiver='" + receiver + '\'' +
                '}';
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MailInfo mailInfo = (MailInfo) o;
        return Objects.equals(sender, mailInfo.sender) && Objects.equals(title, mailInfo.title);
    }

    @Override
    public int hashCode() {
        return Objects.hash(sender, title);
    }

    /**
     * 比较两个 MailInfo对象的大小关系
     * @param o the object to be compared.
     * @return
     */
    @Override
    public int compareTo(MailInfo o) {
        String sender1 = this.getSender();
        String sender2 = o.getSender();
        String title1 = this.getTitle();
        String title2 = o.getTitle();
        int i = sender1.compareTo(sender2);
        if (i == 0){
            int i1 = title1.compareTo(title2);
            return i1;
        }else {
            return i;
        }
    }
}